package com.liy.framework.common.utils;

import com.alibaba.fastjson.serializer.*;
import java.util.*;
import com.alibaba.fastjson.*;
import com.alibaba.fastjson.parser.*;
import org.slf4j.*;

public class FastJsonUtils
{
    private static final Logger logger;
    
    public static final <T> List<T> getList(final String jsontext, final String list_str, final Class<T> clazz) {
        final JSONObject jsonobj = JSON.parseObject(jsontext);
        if (jsonobj == null) {
            return null;
        }
        final Object obj = jsonobj.get((Object)list_str);
        if (obj == null) {
            return null;
        }
        if (obj instanceof JSONArray) {
            final JSONArray jsonarr = (JSONArray)obj;
            final List<T> list = new ArrayList<T>();
            for (int i = 0; i < jsonarr.size(); ++i) {
                list.add((T)jsonarr.getObject(i, (Class)clazz));
            }
            return list;
        }
        return null;
    }
    
    public static final <T> T getObject(final String jsontext, final String obj_str, final Class<T> clazz) {
        final JSONObject jsonobj = JSON.parseObject(jsontext);
        if (jsonobj == null) {
            return null;
        }
        final Object obj = jsonobj.get((Object)obj_str);
        if (obj == null) {
            return null;
        }
        if (obj instanceof JSONObject) {
            return (T)jsonobj.getObject(obj_str, (Class)clazz);
        }
        FastJsonUtils.logger.info(obj.getClass() + "");
        return null;
    }
    
    public static final <T> T getObject(final String jsontext, final Class<T> clazz) {
        T t = null;
        try {
            t = (T)JSON.parseObject(jsontext, (Class)clazz);
        }
        catch (Exception e) {
            FastJsonUtils.logger.error("json\u5b57\u7b26\u4e32\u8f6c\u6362\u5931\u8d25\uff01" + jsontext, (Throwable)e);
        }
        return t;
    }
    
    public static final String toJSONString(final Object object, final boolean prettyFormat) {
        return JSON.toJSONString(object, prettyFormat);
    }
    
    public static final String toJSONString(final Object object) {
        return JSON.toJSONString(object, new SerializerFeature[] { SerializerFeature.WriteMapNullValue });
    }
    
    public static <T> List<T> getList(final String jsonStr, final Class<T> clazz) {
        List<T> list = new ArrayList<T>();
        try {
            list = (List<T>)JSON.parseArray(jsonStr, (Class)clazz);
        }
        catch (Exception e) {
            FastJsonUtils.logger.error("json\u5b57\u7b26\u4e32\u8f6cList\u5931\u8d25\uff01" + jsonStr, (Throwable)e);
        }
        return list;
    }
    
    public static List<Map<String, Object>> listKeyMaps(final String jsonString) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
            list = (List<Map<String, Object>>)JSON.parseObject(jsonString, (TypeReference)new TypeReference<List<Map<String, Object>>>() {}, new Feature[0]);
        }
        catch (Exception e) {
            FastJsonUtils.logger.error("json\u5b57\u7b26\u4e32\u8f6cmap\u5931\u8d25", (Throwable)e);
        }
        return list;
    }
    
    public static Map<String, Object> json2Map(final String jsonStr) {
        try {
            return (Map<String, Object>)JSON.parseObject(jsonStr, (Class)Map.class);
        }
        catch (Exception e) {
            FastJsonUtils.logger.error("json\u5b57\u7b26\u4e32\u8f6c\u6362\u5931\u8d25\uff01" + jsonStr, (Throwable)e);
            return null;
        }
    }
    
    static {
        logger = LoggerFactory.getLogger((Class)FastJsonUtils.class);
    }
}
